import pymysql
from openpyxl import load_workbook
import pso


def myInsert(file):
    try:
        conn = pymysql.connect(host='www.honosayaka.xyz', port=3306, user='boomer', passwd='123456', db='english')
        cursor = conn.cursor()
        index = pso.index
        wb = load_workbook(file)
        sheet = wb['Sheet1']
        for i in range(index, sheet.max_row + 1):
            index1 = 'A' + str(i)
            index2 = 'B' + str(i)
            index3 = 'C' + str(i)
            val1 = sheet[index1].value
            val2 = sheet[index2].value
            val3 = sheet[index3].value
            sql = "insert into vocabulary_copy(voca,mean,unit) values('%s','%s',%s) " % (val1,val2,val3)
            print(sql)
            cursor.execute(sql)

          # 执行插入数据

        conn.commit()
        cursor.close()
        conn.close()
        print('insert ok')
    except Exception as e:
        print(e)


if __name__ == '__main__':
    myInsert()